<%-- 
    Document   : addCustomer
    Created on : 22 Nov, 2012, 8:14:35 PM
    Author     : yogesh
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../common/script.jsp" %>
<!DOCTYPE html>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="../common/title.jsp" %>
        <script type="text/javascript">
            $(function() {
                 
                $( "#followupDate" ).datetimepicker({dateFormat: 'yy-mm-dd',stepMinute:15, hourMin:9,hourMax:21,minDate:0});
                $( "#dateOfBirth" ).datepicker({dateFormat: 'yy-mm-dd',changeMonth:'true',changeYear:'true',yearRange:'1930:+0'} );
                $( "#dateOfJoining" ).datepicker({dateFormat: 'yy-mm-dd',changeMonth:'true',changeYear:'true',yearRange:'1950:+0'});
            });
        </script>
        <script type="text/javascript">

            function disableElement() {
                if(document.getElementById("paymentTypeId.paymentTypeId").value==2 || document.getElementById("relation.relationId").value!=6){
                    document.getElementById("officeLocation.officeId").value = 232;
                    document.getElementById("dependence").value="N/A";
                    document.getElementById("officeLocation.officeId").disabled=true;
                    document.getElementById("dependence").disabled=true;
                    document.getElementById("dateOfJoining").disabled=true;
                }
                
                else{
                    document.getElementById("officeLocation.officeId").disabled=false;
                    document.getElementById("dependence").disabled=false;
                    document.getElementById("dateOfJoining").disabled=false;
                }
                
            }
            function onSubmit(){
                document.getElementById("officeLocation.officeId").disabled=false;
                document.getElementById("dependence").disabled=false;
                document.getElementById("dateOfJoining").disabled=false;
                
            }
            
            //            function test(){
            //                var hosId=document.getElementById("hospitalId").value;
            //            }

            
            //Start //Show ZipCode
            function showZipCode(){
                var zipCode=document.getElementById("zipCodeArea.zipCode").value;
                //alert("inside showZipCode value of zip :"+zipCode);
                $.ajax({
                    data: ({'zipCode1' : zipCode}),
                    url: "../getZipCodeArea.htm",
                    dataType: "json",
                    success:function(json){
                        if(json!=null){
                            //alert("json area: "+json);
                            document.getElementById("area").value=json.area;
                            document.getElementById("masterZone").value=json.masterZone.masterZoneCode;
                            //document.getElementById("zipCodeId").value=json.zipCodeId;
                        }else{
                            document.getElementById("area").value='N/A';
                            document.getElementById("masterZone").value='N/A';
                        }
                    },
                    error: function(e){
                        
                        alert("Error:  Please Enter Zipcode ");
                    }
                });
            }
            //End //Show ZipCode
            
            //FOR DISPOSITION LIST
            //            function showDispositionList(){
            //                var callTypeId=document.getElementById("callType.callTypeId").value;
            //                //alert("insideshowDispositionList value of callTypeId :"+callTypeId);
            //                $.ajax({
            //                    data: ({'callTypeId1' : callTypeId}),
            //                    url: "../ajaxCallForDispositionList.htm",
            //                    dataType: "json",
            //                    success:function(json){
            //                        //alert('inside success event');
            //                        var i=0;
            //                        document.getElementById("dispositionId").length=0;
            //                        
            //                        var anOption1=document.createElement("OPTION");
            //                        document.form1.dispositionId.options.add(anOption1);
            //                        anOption1.text="-";
            //                        anOption1.value="";
            //                        for(i=0;i<json.length;i++){
            //                            //alert('inside if ');
            //                            var anOption=document.createElement("OPTION");
            //                            document.form1.dispositionId.options.add(anOption);
            //                            //alert('anOption.text: '+anOption.text);
            //                            anOption.text=json[i].label;
            //                            anOption.value=json[i].value;
            //                        }
            //                    },
            //                    error: function(e){
            //                        
            //                        alert("Error:  method not called ");
            //                    }
            //                });
            //            }
            //End
             
            
                        
        </script>
        <!--        <script type="text/javascript">
                    $(function() {
                        $( "#hospitalId" ).autocomplete({
                            source: "../ajaxCallForHospitalList.htm",
                            minLength: 1    
                        });
                    });
                </script>
                <script type="text/javascript">
                    $(function() {
                        $( "#appSpecialistId" ).autocomplete({
                            source: "../ajaxCallForAppSpecialist.htm",
                            minLength: 1    
                        });
                    });
                </script>-->
        <script type="text/javascript">
            var illnessFlag=0;
            var rules=new Array();
            rules[0]='paymentTypeId.paymentTypeId|required|please Select customer type';
            rules[1]='relation.relationId|required|please Select Relation';
            rules[2]='age|mask|0123456789';
            rules[3]='age|maxlength|3|maximum 3 digits are allowed';
            rules[4]='callType.callTypeId|required|please Select CallType';
            rules[5]='dispositionId|required|please Select Disposition';
            rules[6]='phone1|maxlength|10|please enter only 10 digit no';
            rules[7]='phone1|mask|0123456789';
            rules[8]='phone2|maxlength|10|please enter only 10 digit no';
            rules[9]='phone2|mask|0123456789';
            rules[10]='bloodGroup|required|please select blood group';
            rules[11]='emailId|email|email must be a valid e-mail.';
            rules[12]='empId|maxlength|6|maximum 6 digits are allowed';
            rules[13]='officeLocation.officeId|required|please select office location';
            rules[14]='healthSpringCenter.centerId|required|please select center';
            rules[15]='zipCodeArea.zipCode|mask|0123456789';
            rules[16]='zipCodeArea.zipCode|maxlength|6|maximum 6 digits are allowed';
            rules[17]='gender|required|please select gender';
            //rules[18]='followupDate|custom|followupDate1()';
            rules[18]='food|custom|checkBlankFields()';
            rules[19]='drug|custom|checkBlankFields()';
            rules[20]='otherAllergies|custom|checkBlankFields()';
            rules[21]='final_tiers|custom|checkBlankFields()';
            rules[22]='otherIllness|custom|checkBlankFields()';
            rules[23]='recordingId|required|please enter call recording id';
            rules[24]='notes|required|please enter notes';
            //            rules[25]='maritalStatus|required|Select marital status';
            
        </script>
        <script type="text/javaScript">
    
            function addOption(selectbox,text,value) {
                var optn = document.createElement("OPTION");
                optn.text = text;
                optn.value = value;
                selectbox.options.add(optn);
            }
    
            function moveRight(){
               
                var rightBox=document.form1.final_tiers;
                var leftBox=document.form1.left_out;
                var moved=0;
                for (var i=0; i<leftBox.length+moved; i++) {
                    if (leftBox.options[i-moved].selected == true) {
                        addOption(rightBox,leftBox.options[i-moved].text,leftBox.options[i-moved].value);
                        leftBox.remove(i-moved);
                        moved++;
                    }
                }
            }
            function moveLeft(){
              
                var rightBox=document.form1.final_tiers;
                var leftBox=document.form1.left_out;
                var moved=0;
                for (var i=0; i<rightBox.length+moved; i++) {
                    if (rightBox.options[i-moved].selected == true) {
                        addOption(leftBox,rightBox.options[i-moved].text,rightBox.options[i-moved].value);
                        rightBox.remove(i-moved);
                        moved++;
                    }
                }
            }
    
            function validateForm()
            {
                var rightBox=document.form1.final_tiers;
                
                var viewTiers="";
                document.form1.selectedIllnessIds.value="";
                for (var i=0; i<rightBox.length; i++) {
                    viewTiers += rightBox.options[i].value + ",";
                }
                viewTiers = viewTiers.substr(0, (viewTiers.length-1));
                
                document.form1.selectedIllnessIds.value=viewTiers;
                
                return true;
            }
            
            function  updateAge() {
                document.getElementById('age').value=getAge(document.getElementById('dateOfBirth').value);
            }
            
            function checkBlankFields() {
                
                if(illnessFlag==0) {
                    //alert("("+document.getElementById("food").value+")");
                    if(document.getElementById("food").value=="" || document.getElementById("drug").value=="" || document.getElementById("drug").value=="" || document.getElementById("otherAllergies").value==""  ) {
                        illnessFlag=1;
                        return "Warning.You have not selected Alergies.";
                    } else if (document.getElementById("final_tiers").value=="" || document.getElementById("otherIllness").value=="") {
                        illnessFlag=1;
                        return "Warning.You have not selected  Known Illnesses.";
                        //return null;
                    }
                    else{
                        return null;
                    }
                } else {
                    return null;
                }
            }
        </script>
    </head>
    <body style="margin:0; padding:0;" onLoad="yav.init('form1',rules,'inline');">
        <%@include file="../common/header.jsp" %>
        <%@include file="../common/menu.jsp" %>
        <div class="in_02">
            <%@include file="../common/message.jsp" %>
            <form:form id="form1" name="form1"  modelAttribute="customer" cssClass="userInputForm" >

                <input type="hidden" name="customerId" value="${customer.customerId}"/>
                <fieldset style="width:950px;">
                    <legend><spring:message code="title.addCustomer"/></legend>
                    <table class="formTable">
                        <tr>
                            <td>
                                <fieldset>
                                    <legend>Customer Info</legend>
                                    <table class="formTable1">
                                        <tr>

                                            <td>
                                                <spring:message code="activeForCustomer"/>:<br/>
                                                <form:radiobutton cssClass="gender" path="active" value="true" cssStyle="margin:0 -20px 0 0;" /><spring:message code="yes"/>&nbsp;
                                                <form:radiobutton cssClass="gender" path="active" value="false" cssStyle="margin:0 -20px 0 0;" /><spring:message code="no"/>
                                            </td>
                                            <td> <spring:message code="important"/>:<br/>
                                                <form:radiobutton cssClass="gender" path="important" value="true" cssStyle="margin:0 -20px 0 0;" /><spring:message code="yes"/>&nbsp;
                                                <form:radiobutton cssClass="gender" path="important" value="false" cssStyle="margin:0 -20px 0 0;" /><spring:message code="no"/>
                                            </td>

                                        </tr>
                                        <tr>
                                            <td><spring:message code="mrNo"/>:<br/> 
                                                <form:input path="mrNo" cssClass="userInputLarge" /><br/>
                                            </td>
                                            <td><spring:message code="familyCode"/>:<br/> 
                                                <form:input path="familyCode" cssClass="userInputLarge" /><br/>
                                            </td>
                                            <td><spring:message code="empId"/>:<br/> 
                                                <form:input path="empId" cssClass="userInputLarge"/><br/>
                                                <br><span id="errorsDiv_empId"></span>
                                            </td>
                                            <td><spring:message code="patientName"/>:<br/> 
                                                <form:input path="customerName" cssClass="userInputLarge"/><br/>
                                            </td>
                                        </tr>

                                        <tr>

                                            <td><spring:message code="phone1"/>:<br/> 
                                                <form:input path="phone1" cssClass="userInputLarge"/><br/>
                                                <span id="errorsDiv_phone1"></span><br/>
                                            </td>
                                            <td><spring:message code="phone2"/>:<br/> 
                                                <form:input path="phone2" cssClass="userInputLarge"/><br/>
                                                <span id="errorsDiv_phone2"></span><br/>
                                            </td>
                                            <td><spring:message code="emailId"/>:<br/><form:input  path="emailId"  class="userInputLarge"/>
                                                <span id="errorsDiv_emailId"></span><br/>
                                            </td>
                                            <td><spring:message code="customerType"/>:<br/>
                                                <form:select  path="paymentTypeId.paymentTypeId" id="paymentTypeId.paymentTypeId" cssClass="userInputMedium"  onchange="disableElement();" onblur="disableElement();">
                                                    <form:option value="" label="-"></form:option>
                                                    <form:options items="${paymentTypeList}" itemLabel="paymentTypeName" itemValue="paymentTypeId"></form:options>
                                                </form:select><br/>
                                                <span id="errorsDiv_paymentTypeId.paymentTypeId"></span><br/>
                                            </td>

                                        </tr>

                                        <tr>
                                            <td><spring:message code="dateOfBirth"/>:<br/>
                                                <input name="dateOfBirth"  id="dateOfBirth" class="userInputLarge" onchange="updateAge();"/>
                                            </td>
                                            <td>
                                                <spring:message code="age"/>:<br/> 
                                                <%--<form:input path="age" cssClass="userInputLarge" readonly="true"/><br/> --%>
                                                <input type="text" onload="updateAge();" readonly="true" name="age" id="age">
                                                <br><span id="errorsDiv_age"></span>
                                            </td>
                                            <td>
                                                <spring:message code="gender"/>:<br/>
                                                <form:select  path="gender"  cssClass="userInputMedium">
                                                    <form:option value="" label="-"></form:option>
                                                    <form:option value="Male" label="-">Male</form:option>
                                                    <form:option value="Female" label="-">Female</form:option>
                                                    <form:option value="U" label="-">U</form:option>
                                                    <form:option value="Not Known" label="-">Not Known</form:option>
                                                </form:select><br/>
                                                <span id="errorsDiv_gender"></span><br/>
                                            </td>
                                            <td><spring:message code="bloodGroup"/>:<br/>
                                                <form:select  path="bloodGroup"  cssClass="userInputMedium">
                                                    <form:option value="" label="-"></form:option>
                                                    <form:option value="A+" label="-">A+</form:option>
                                                    <form:option value="A-" label="-">A-</form:option>
                                                    <form:option value="B+" label="-">B+</form:option>
                                                    <form:option value="B-" label="-">B-</form:option>
                                                    <form:option value="AB+" label="-">AB+</form:option>
                                                    <form:option value="AB-" label="-">AB-</form:option>
                                                    <form:option value="O+" label="-">O+</form:option>
                                                    <form:option value="O-" label="-">O-</form:option>
                                                    <form:option value="Not Known" label="-">Not Known</form:option>
                                                </form:select><br/>
                                                <span id="errorsDiv_bloodGroup"></span><br/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><spring:message code="maritalStatus"/>:<br/>
                                                <form:select  path="maritalStatus"  cssClass="userInputMedium">
                                                    <form:option value="" label="-"></form:option>
                                                    <form:option value="Widowed">Widowed</form:option>
                                                    <form:option value="Separated">Separated</form:option>
                                                    <form:option value="Divorced">Divorced</form:option>
                                                    <form:option value="Dependents">Dependents</form:option>
                                                </form:select><br/>
                                                <!--                                                <span id="errorsDiv_maritalStatus"></span><br/>-->
                                            </td>
                                            <td>Cost center<br/><form:input path="costCenter" cssClass="userInputLarge"/></td>
                                            <td colspan="1">
                                                <spring:message code="eligible"/>:<br/>
                                                <form:radiobutton cssClass="gender" path="eligible" value="true" /><spring:message code="yes"/>&nbsp;
                                                <form:radiobutton cssClass="gender" path="eligible" value="false" /><spring:message code="no"/>
                                            </td>
                                            <td colspan="1"><spring:message code="remainInContactVia"/>:<br/>
                                                <form:checkbox path="sms" value="true" label="Sms" cssStyle="margin:0 -20px 0 0;"></form:checkbox>
                                                <form:checkbox path="email" value="true" label="Email" cssStyle="margin:0 -20px 0 0;"></form:checkbox>
                                                </td>

                                            </tr>
                                            <tr>
                                                <td><spring:message code="relation"/>:<br/>
                                                <form:select  path="relation.relationId" id="relation.relationId" cssClass="userInputMedium" onchange="disableElement();" onblur="disableElement();">
                                                    <form:option value="" label="-"></form:option>
                                                    <form:options items="${relationList}" itemLabel="relationName" itemValue="relationId"></form:options>
                                                </form:select><br/>
                                                <span id="errorsDiv_relation.relationId"></span><br/>
                                            </td>
                                            <td>
                                                <spring:message code="noOfDependence"/>:<br/>
                                                <form:select  path="dependence" id="dependence" cssClass="userInputMedium">
                                                    <form:option value="0" label="-">0</form:option>
                                                    <form:option value="1" label="-">1</form:option>
                                                    <form:option value="2" label="-">2</form:option>
                                                    <form:option value="3" label="-">3</form:option>
                                                    <form:option value="4" label="-">4</form:option>
                                                    <form:option value="5" label="-">5</form:option>
                                                    <form:option value="6" label="-">6</form:option>
                                                    <form:option value="7" label="-">7</form:option>
                                                    <form:option value="8" label="-">8</form:option>
                                                    <form:option value="9" label="-">9</form:option>
                                                    <form:option value="N/A" label="-">N/A</form:option>
                                                </form:select>
                                            </td>
                                            <td><spring:message code="dateOfJoining"/>:<br/>
                                                <input name="dateOfJoining"  id="dateOfJoining" class="userInputLarge"/>
                                            </td>
                                            <td>
                                                <spring:message code="officeLocation"/>:<br/>

                                                <form:select  path="officeLocation.officeId" id="officeLocation.officeId" cssClass="userInputLarge">
                                                    <form:option value="" label="-"></form:option>
                                                    <form:options items="${officeList}" itemLabel="officeLocation" itemValue="officeId" ></form:options>
                                                </form:select><br/>
                                                <span id="errorsDiv_officeLocation.officeId"/><br/>
                                            </td>   
                                        </tr>
                                        <tr>

                                            <td><spring:message code="address1"/>:<br/> 
                                                <form:textarea path="address" cssClass="userInputLarge"/><br/>
                                            </td>
                                            <td><spring:message code="address2"/>:<br/> 
                                                <form:textarea path="road" cssClass="userInputLarge"/><br/>
                                            </td>
                                            <td><spring:message code="landmark"/>:<br/> 
                                                <form:input path="landmark" cssClass="userInputLarge"/><br/>
                                            </td> 
                                            <td>
                                                <spring:message code="pinCode"/>:<br/>
                                                <%-- HIDDEN FIELD FOR PASSING ZIPCODEID TO STORE INTO CUSTOMER OBJECT--%>
                                                <%-- <input type="hidden" name="zipCodeId" id="zipCodeId">--%>

                                                <form:input path="zipCodeArea.zipCode" cssClass="userInputLarge" onchange="showZipCode();"/><br/>

                                                <span id="errorsDiv_zipCodeArea.zipCode"></span><br/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Area :<br/>
                                                <input type="text" name="area" id="area" class="userInputMediumReadOnly" readonly>
                                            </td>
                                            <td>MasterZone :<br/>
                                                <input type="text" name="masterZone" id="masterZone" class="userInputMediumReadOnly" readonly>
                                            </td>


                                            <td><spring:message code="prefferdCenter"/>:<br/>
                                                <form:select  path="healthSpringCenter.centerId"   cssClass="userInputMedium">
                                                    <form:option value="" label="-"></form:option>
                                                    <form:options items="${centerList}" itemLabel="centerName" itemValue="centerId"></form:options>
                                                </form:select><br/>
                                                <span id="errorsDiv_healthSpringCenter.centerId"></span><br/>
                                            </td>
                                            <td><spring:message code="registrationStatus"/>:<br/>
                                                <form:select  path="registrationStatus"  cssClass="userInputMedium">
                                                    <form:option value="Not Started" label="-">Not Started</form:option>
                                                    <form:option value="Pending" label="-">Pending</form:option>
                                                    <form:option value="Completed" label="-">Completed</form:option>
                                                </form:select><br/>
                                            </td>
                                        </tr>

                                    </table>
                                </fieldset>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <fieldset>
                                    <legend><spring:message code="knownAllergy"/></legend>
                                    <table class="formTable">

                                        <tr>
                                            <td><spring:message code="food"/>:<br/>
                                                <form:input path="food" cssClass="userInputLarge"/><br/>
                                                <span id="errorsDiv_food"></span>
                                            </td> 
                                            <td><spring:message code="drug"/>:<br/>
                                                <form:input path="drug" cssClass="userInputLarge"/><br/>
                                                <span id="errorsDiv_drug"></span>
                                            </td>

                                            <td><spring:message code="other"/>:<br/>
                                                <form:textarea path="otherAllergies" cssClass="userInputLarge"/><br/>
                                                <span id="errorsDiv_otherAllergies"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <fieldset>
                                    <legend><spring:message code="knownIllness"/></legend>
                                    <table class="formTable1">
                                        <tr>
                                            <td>Available Illnesses :<br/> 
                                                <select name="left_out" class="user-input" id="left_out" multiple size="10" style="width: 260px"></select></td>
                                            <td align="center" valign="center" class="script">
                                                <br/><br/><br/>
                                                <input type="button" value="<<" onClick="moveLeft();" name="leftButton" class="less_btn" />
                                                <br/><br/><br/>
                                                <input type="button" value=">>" onClick="moveRight();" name="rightButton" class="less_btn" /></td>
                                            <td>Selected Illnesses :<br/>
                                                <select name="final_tiers" id="final_tiers" class="user-input" multiple size="10" style="width: 260px"></select>
                                                <span id="errorsDiv_final_tiers"></span></td>
                                        </tr>  
                                        <tr>
                                            <td colspan="2"><spring:message code="otherIllness"/>:<br/>
                                                <form:textarea path="otherIllness" cssClass="userInputLarge"/><br/>
                                                <span id="errorsDiv_otherIllness"></span></td>
                                        </tr> 
                                    </table>
                                </fieldset>
                            </td>
                        </tr>


                        <tr>
                            <td align="left">
                                <input type="button" name="button" value="CANCEL" onclick="location.href='../customer/searchCustomerCommonHeader.htm'"  >
                            </td>

                            <td align="right">
                                <input type="submit"  name="button" value="SUBMIT" onclick=" validateForm();onSubmit();return yav.performCheck('form1', rules, 'inline'); "  />
                            </td>

                        </tr>

                    </table>


                    <input type="hidden" name="selectedIllnessIds" id="selectedIllnessIds"/>
                    <script laguage="javascript">
                        var rightBox=document.form1.final_tiers;
                        var leftBox=document.form1.left_out;
                        <c:forEach items="${illnessList}" var="parameter">
                            addOption(leftBox,'${parameter.illnessName}','${parameter.illnessId}');
                        </c:forEach>
                        <c:forEach items="${selectedIllnessList}" var="parameter">
                            addOption(rightBox,'${parameter.illnessName}','${parameter.illnessId}');
                        </c:forEach>
                    </script>


                </fieldset>
            </form:form>
        </div>

    </body>
</html>